<% @main_header = "#{link_to('Ptrack:', '/')} #{link_to(@activity.project.name,project_url(@activity.project))}: #{@activity.phase.name}" %>
<%= error_messages_for 'collection',:object_name=>nil,:header_message=>nil,:class=>'error' %>
<%= display_messages_for_all %>

<h3><%= link_to 'Create New Task', new_task_for_activity_url(@activity.project_id, @activity.id) %></h3>
<div class="column span-8 colborder">
  <b>Weight: </b><%=@activity.weight %> %<br/>
  <br/>

  <% unless @tasks_waiting_for_approval.empty? %>
    <p>
      <h4>Tasks Waiting for Approval:</h4>
    </p>
    <% for task_w in @tasks_waiting_for_approval %>
      <%= '<img title="' + task_w.status.to_s + '" src="/images/' +
        task_w.status.to_s.downcase.tr(' ', '') +
        '.png" alt="' + task_w.status.to_s  + '" />' %>
      <%= link_to task_w.name, project_task_path(@activity.project,task_w) %>
      <% if task_w.status.eql?("Waiting for Approval")%>
        <%= link_to image_tag("/images/approved.png") + "Approve",approve_task_url(@project.id,task_w.id),:confirm=>"Are you sure you want to approve this task?" %>
    <br/>
    <% end %>
    <% end %>
    <br><br>
    <hr>
  <%  end %>

  <% unless @tasks.empty? %>
    <p>
      <h4>Tasks:</h4>
    </p>
    <% for task in @tasks %>
      <%= '<img title="' + task.status.to_s + '" src="/images/' +
        task.status.to_s.downcase.tr(' ', '') +
        '.png" alt="' + task.status.to_s  + '" />' %>
      <%= link_to task.name, project_task_path(@activity.project,task) %>
      <% if task.status.eql?("Waiting for Approval") and  current_user.is_admin %>
        <%= link_to image_tag("/images/approved.png") + "Approve",approve_task_url(@project.id,task.id),:confirm=>"Are you sure you want to approve this task?" %>
      <% end %>
      <br />

    <% end %>
  <%end %>
</div>

<div class="span-15 last">
  <% if @activity.collection_percent_total < 100 %>
    <%= link_to_function image_tag('/images/add.png') + "Add Money Collection" , "$('#add_new_collection').show();"  %>
  <% end %>
  <div id="add_new_collection" style="display:<%= @display_form  %>">
    <h3>Add New Money Collection</h3>
    <% form_for @collection,:url=>new_collection_url(@project.id,@activity.id) do |f| %>
      <%= hidden_field :activity ,:id  %>
      <table cellpadding="2" cellspacing="2">
        <tr>
          <td><%= f.label 'amount', 'Collected Amount:' %></td>
          <td><%= f.text_field 'amount', :size => 20 %>
        </tr>
        <tr>
          <td><%= f.label 'currency', 'Currency:' %></td>
          <%  unless @project.currency=='TL' %>
            <td><%= f.select :currency, [["TL","TL"],[@project.currency,@project.currency]] %> </td>
          <%  else %>
            <td><%= f.select :currency, [["TL","TL"]] %> </td>
          <%end%>
        </tr>
        <% unless @project.currency=='TL' %>
          <tr>
            <td><%= f.label 'currency_rate', "Currency Rate #{@project.currency}/TL :" %></td>
            <td><%= f.text_field 'currency_rate', :size => 20 %></td>
          </tr>
        <%  end %>
        <tr>
          <td><%= f.label 'percent', 'Phase Percent % :' %></td>
          <td><%= f.text_field 'percent', :size => 20 %> </td>
        </tr>
        <tr>
          <td><%= f.label 'collection_date', 'Collection Date:' %></td>
          <td><%= f.text_field 'collection_date', :size => 20 %> </td>
        </tr>
        <tr><td colspan="2"> <%= submit_tag 'Add' %></td></tr>
      </table>
    <%  end %>

  </div>
  <p>
    <b>Expected Amount : </b><%= format_number @activity.estimated_cost_in_project %> <%=@activity.project.currency  %><br>
    <% if @project.is_foreign_currency %>
      <b>Total Collected Amount (<%=@project.currency%>) : </b><%= format_number @activity.collection_amount_total(true) %> <%=@project.currency  %><br>
    <%  end %>
    <b>Total Collected Amount (TL) : </b><%= format_number @activity.collection_amount_total(false) %> TL<br>
    <b>Total Percent Collected For This Phase : </b><%=
    if @activity.collection_percent_total<100
      @activity.collection_percent_total
    else 100
    end
  %> %<br>
  </p>
  <p><b>Money Collections:</b></p>
  <div>
    <% for cllctn in @collections %>
      <ul>
        <li>
          <% if ["USD","EUR"].include?(cllctn.currency):  %>
            <b>Collected Amount (<%= cllctn.currency %>) : </b><%= format_number cllctn.amount %>&nbsp;<%= cllctn.currency %><br />
          <% end %>
          <b>Collected Amount (TL) : </b><%= format_number cllctn.amount * ( ["USD","EUR"].include?(cllctn.currency) ? cllctn.currency_rate : 1) %>&nbsp;TL<br />
          <% if  @project.currency!='TL' or cllctn.currency!='TL' %>
            <b>Collection Currency Rate (on
              <%=  unless cllctn.collection_date.nil?
                cllctn.collection_date.strftime('%d %b %Y')
              else cllctn.created_at.strftime('%d %b %Y')
              end%>): </b><%= number_with_precision(cllctn.currency_rate,4)%> <%= @project.currency %> / TL<br />
            <%end%>
          <b>Phase Percent: </b> <%= cllctn.percent %> %<br />
          <b>Collection Added By : </b> <%= cllctn.user.login %><br />
          <b>Collected On : </b> <%=
          unless cllctn.collection_date.nil?
            cllctn.collection_date.strftime('%d %b %Y')
          else cllctn.created_at.strftime('%d %b %Y')
          end
        %>          <br>
          <%= link_to "Remove",{:controller=>'activities',:action=>"destroy_collection",:id=>cllctn.id},
            :confirm=>"Are you sure you want to delete this money collection?" %>
        </li>
      </ul>
    <% end if @collections.length > 0%>
  </div>
  <hr>


</div>